package com.bac.bacplatform;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.bac.utils.Config;
import com.bac.utils.Util;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MyDialog extends Dialog implements
		android.view.View.OnClickListener, ErrorListener {

	Context context;

	private Button btn_cancle;
	private Button btn_ok;
	private EditText error_suggest;

	public MyDialog(Context context, int theme) {
		super(context, theme);
		this.context = context;
	}

	public MyDialog(Context context) {
		super(context);
		this.context = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.errordialog);

		btn_cancle = (Button) findViewById(R.id.btn_cancle);
		btn_cancle.setOnClickListener(this);
		btn_ok = (Button) findViewById(R.id.btn_ok);
		btn_ok.setOnClickListener(this);
		error_suggest = (EditText) findViewById(R.id.error_suggest);
	}

	/**
	 * 加油站信息纠错
	 */
	public boolean feedback() {
		/**
		 * 成功返回结果
		 */
		Listener<String> sL = new Response.Listener<String>() {
			@Override
			public void onResponse(String response) {
				Log.i("TAG----success", response.toString());
			}
		};

		if(error_suggest.getText().toString().length()==0){
			return false;
		}
		String path = Config.URL_GAS_COMMENT;
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", GasInformationActivity.location.getId() + "");
		map.put("content", error_suggest.getText().toString());
		Util.httpStringPost(path, sL, (GasInformationActivity)this.context, map);
		return true;
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.btn_cancle:
			dismiss();
			break;
		case R.id.btn_ok:
			if(feedback()){
				dismiss();
			}
			break;

		default:
			break;
		}
	}

	@Override
	public void onErrorResponse(VolleyError arg0) {
	}
}
